const jwt = require('jsonwebtoken');

const list = async ctx => {
	const { name, age } = ctx.request.query
	ctx.body = {
		name,
		age
	}
}

const login = async ctx => {
	const { username, password } = ctx.request.body
	ctx.body = {
		token: jwt.sign({
			username,
		}, 'biluo_koa', { expiresIn: '2h' })
	}
}

const saveUser = async ctx => {
	const { service,request } = ctx
	const user = request.body
	const res = await service.user.save(user)
	console.log(res);
	ctx.body = res
}

module.exports = {
	list,
	login,
	saveUser
}
